package org.redis.cluster.transport.client;

import org.redis.cluster.RedisCluster;
import org.redis.cluster.plugin.Plugin;

public class ClientPoolFactory implements Plugin {

	private final static String CLIENT_POOL="clientPool";
	
	private static RedisCluster redisCluster;
	
	private static ClientPool clientPool;

	@Override
	public void init(RedisCluster redisCluster) {
		this.redisCluster=redisCluster;
	}

	@Override
	public void destroy() {
		
	}
	
	protected static ClientPool initClientFactory() {
		return redisCluster.getExtensionLoader().load(CLIENT_POOL,ClientPool.class);
	}
	
	public static ClientPool getClientPool() {
		if(clientPool!=null) {
			return clientPool;
		}
		
		synchronized (ClientPoolFactory.class) {
			if(clientPool!=null) {
				return clientPool;
			}
			
			clientPool=initClientFactory();
			return clientPool;
		}
	}
}